// newlib includes
#include <stdio.h>
#include <sys/stat.h>

// entry point
int main( int argc, char* argv[] )
{	
	printf( "testing out file i/o...\n" );
	
	/*printf( "testing a theory: %s\n", ("hello\nworld\r\nthis is a test\n") + 8 );
	
	char* tmp = (char*) malloc( 1024 );
	sprintf( tmp, "testing a theory: %s\n", "hello\nworld\r\nthis is a test\n" );
	printf( "%s\n", tmp + 8 );
	free( tmp );
	
	fflush( stdout );
	fflush( stderr );
	
	while( 1 );
	
	int fd = open( "/ramfs/test.asm", 0 );
	struct stat s;
	printf( "sizeof( struct stat ) = %d\n", sizeof( struct stat ) );
	s.st_size = 1234;
	fstat( fd, &s );
	printf( "file size = %d bytes\n", s.st_size );
	lseek( fd, 0, SEEK_SET );
	char* buff = (char*) malloc( s.st_size + 1 );
	read( fd, buff, s.st_size );
	printf( "Read in: %s\n", buff );
	close( fd );
	free( buff );*/
	
	setvbuf( stdin, 0, _IONBF, 0 );
	
	printf( "hello world: %s\n", "hello\nworld" );
	
	char c = getchar();
	printf( "read: %c\n", c );
	
	char tmp[32];
	fread( tmp, 1, 32, stdin );
	printf( "Read in %s!\n\n", tmp );
	
	/*
	FILE* fp = fopen( "/ramfs/test.asm", "rw" );
	printf( "Reading...\n" );
	char tmp[64];
	if( fp )
	{
		fseek( fp, 0, SEEK_SET );
		while( !feof( fp ) )
		{
			memset( tmp, 0, 64 );
			fread( tmp, sizeof( char ), 32, fp );
		}
		fclose( fp );
	}
	printf( "%s\n", tmp );
	int i;
	for( i = 0; i < 15; i++ )
		printf( "Character %d: %c\n", i, tmp[i] );
	printf( "done reading?\n" );
	*/
	fflush( stdout );
	fflush( stderr );
	
	// end the process
	kill( getpid() );
	while( 1 );
}
